package com.sicheng.lc.周赛.分类.贪心.区间问题;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/31 20:43
 */
@SuppressWarnings("all")
public class 区间选点 {
    //https://www.acwing.com/problem/content/description/907/
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] e = new int[n][2];
        for (int i = 0; i < n; i++) {
            e[i][0] = in.nextInt();
            e[i][1] = in.nextInt();
        }
        Arrays.sort(e, Comparator.comparingInt(a -> a[1]));

        int last = Integer.MIN_VALUE;
        long res = 0;
        for (int[] d : e) {
            if (last == Integer.MIN_VALUE || d[0] > last) {
                last = d[1];
                res++;
            }
        }

        System.out.println(res);
    }
}
